package L1;

import java.util.Scanner;

public class _019 {

	public static void main(String[] args) {
		Scanner reader=new Scanner(System.in);
		int Acapacity=reader.nextInt(),Bcapacity=reader.nextInt();
		int number=reader.nextInt();
		int total[]=new int[number];
		int str1[]=new int[number];
		int str2[]=new int[number];
		for(int i=0;i<number;i++)
		{
			total[i]=reader.nextInt();
			str1[i]=reader.nextInt();
			total[i]+=reader.nextInt();
			str2[i]=reader.nextInt();
		}
		int a=0,b=0;
		for(int i=0;i<number;i++)
		{
			if(total[i]==str1[i]&&total[i]!=str2[i])
			{
				a++;
				if(a==Acapacity+1)
				{
					System.out.println("A");
					System.out.println(b);
					break;
				}
			}
			if(total[i]==str2[i]&&total[i]!=str1[i])
			{
				b++;
				if(b==Bcapacity+1)
				{
					System.out.println("B");
					System.out.println(a);
					break;
				}
			}
			/*
			if(total[i]==str2[i]&&total[i]==str1[i])
			{
				a++;
				if(a==Acapacity+1)
				{
					System.out.println("A");
					System.out.println(b);
					break;
				}
				b++;
				if(b==Bcapacity+1)
				{
					System.out.println("B");
					System.out.println(a);
					break;
				}
			}*/
		}
		reader.close();
	}
}
 